//
//  HBComposeButton.swift
//  sinaWeibo
//
//  Created by Beans on 16/6/29.
//  Copyright © 2016年 iceWorks. All rights reserved.
//

import UIKit

class HBComposeButton: UIButton {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupUI() {

        // 设置属性
        setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(16.0)
        titleLabel?.textAlignment = .Center

        // 设置图片的contentMode
        imageView?.contentMode = .Center
    }

    override func layoutSubviews() {
        super.layoutSubviews()

        // 设置image的frame
        var imageFrame = imageView?.frame
        imageFrame?.size = CGSizeMake(bounds.width, bounds.width)
        imageFrame?.origin.x = 0
        imageFrame?.origin.y = 0
        imageView?.frame = imageFrame!

        var labelFrame = titleLabel?.frame
        labelFrame?.size = CGSizeMake(bounds.width, bounds.height - bounds.width)
        labelFrame?.origin.x = 0
        labelFrame?.origin.y = bounds.width
        titleLabel?.frame = labelFrame!
    }
}
